package com.xy.netutils.net;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.util.Log;

import rx.Subscriber;

/**
 * Created by 向阳 on 2016/11/23.
 * email：yang.xiang@cienet.com.cn
 */

public  abstract class BaseSubscriber<T> extends Subscriber<T> {

    private Context mContext;
    private ProgressDialog progressDialog;

    public BaseSubscriber(Context context)
    {
        mContext=context;
        progressDialog = new ProgressDialog(mContext);
        progressDialog.setMessage("正在加载数据，请稍后...");
    }

    @Override
    public void onStart() {
        super.onStart();
        Log.d("BaseSubscriber", "onStart");
        progressDialog.show();
    }

    @Override
    public  void onCompleted(){
        progressDialog.dismiss();
    }

    @Override
    public void onError(Throwable e){
        progressDialog.dismiss();
        final AlertDialog.Builder builder=new AlertDialog.Builder(mContext);
        builder.setMessage(e.getMessage()).setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                builder.create().dismiss();
            }
        });
        builder.show();
    }

    @Override
    public abstract void onNext(T t);



}
